package cn.jb698.codec.msm.generator.v5base.beans;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import cn.jb698.codec.msm.generator.util.CodecDbConnectionUtils;

/**
 * 基础增删改查的全局配置Bean
 * 
 * @author SDPC_LIU
 *
 */
public class BcrudConfigBean {

	/**
	 * 数据库类型,默认Mysql
	 */
	private String dbType = CodecDbConnectionUtils.DB_DIALECT_MYSQL ;
	
	/**
	 * 驱动类
	 */
	private String dbDriverClassName;

	/**
	 * 连接地址
	 */
	private String dbConnectionUrl;

	/**
	 * 数据库用户名.
	 */
	private String dbUserName;

	/**
	 * 数据库密码.
	 */
	private String dbPassword;

	/**
	 * 项目包名
	 */
	private String projPackageName;

	/**
	 * 基础包名,例: com.project.bcrud
	 */
	private String basePackageName;
	
//	/**
//	 * Ctrler层基本包名,例: com.projxx.modelxx.ctrler
//	 */
//	private String apiPackageName; 
	
	/**
	 * 项目级别根路径,例: D:/workspace/project_codec/
	 */
	private String projRootDir ;

	/**
	 * JSON 文件输出目录. 例: D:/workspace/project_codec/codec/bcrud/tablejsons/
	 */
	private String jsonFileOutDir;

	/**
	 * Java 代码输出根路径, 例: D:/workspace/project_codec/src/main/java/
	 */
	private String javaCodeRootDir;

	/**
	 * 资源文件 代码输出根路径, 例: D:/workspace/project_codec/src/main/resources/
	 */
	private String resCodeRootDir;

	/**
	 * 页面 代码输出路径, 例: D:/workspace/project_codec/src/main/webapp/WEB-INF/jsp/bcrud/
	 */
	private String pageCodeRootDir; 
	
	/**
	 * 是否生成Service层代码,默认true
	 */
	private boolean hasCreateService =true ;
	
	/**
	 * 是否生成Ctrler,默认false
	 */
	private boolean hasCreateCtrler = false ; 
	
	/**
	 * 是否生成页面(ui层),默认false
	 */
	private boolean hasCreatePage = false ; 

	/**
	 * Mapper.xml 文件输出包名  
	 */
	private String mapperXmlPackageName ; 

	/**
	 * 数据库表列表.
	 */
	private List<BcrudCfgTableObj> cfgTables = new ArrayList<>(); // 要生成的表数组.

	/**
	 * 其它层模板输出模板配置
	 */
	private List<FileOutputTpltCfg> fileOutputTpltCfgList = new ArrayList<>() ;


	public String getDbDriverClassName() {
		return dbDriverClassName;
	}

	public void setDbDriverClassName(String dbDriverClass) {
		this.dbDriverClassName = dbDriverClass;
	}

	public String getDbConnectionUrl() {
		return dbConnectionUrl;
	}

	public void setDbConnectionUrl(String dbConnectionUrl) {
		this.dbConnectionUrl = dbConnectionUrl;
	}

	public String getDbUserName() {
		return dbUserName;
	}

	public void setDbUserName(String dbUserName) {
		this.dbUserName = dbUserName;
	}

	public String getDbPassword() {
		return dbPassword;
	}

	public void setDbPassword(String dbPassword) {
		this.dbPassword = dbPassword;
	}

	public String getJsonFileOutDir() {
		return jsonFileOutDir;
	}

	public void setJsonFileOutDir(String jsonFileOutDir) {
		this.jsonFileOutDir = jsonFileOutDir;
	}

	public String getBasePackageName() {
		return basePackageName;
	}

	public void setBasePackageName(String basePackageName) {
		this.basePackageName = basePackageName;
	}

	public String getJavaCodeRootDir() {
		return javaCodeRootDir;
	}

	public void setJavaCodeRootDir(String javaCodeRootDir) {
		this.javaCodeRootDir = javaCodeRootDir;
	}

	public String getResCodeRootDir() {
		return resCodeRootDir;
	}

	public void setResCodeRootDir(String resCodeRootDir) {
		this.resCodeRootDir = resCodeRootDir;
	}

	public String getPageCodeRootDir() {
		return pageCodeRootDir;
	}

	public void setPageCodeRootDir(String pageCodeRootDir) {
		this.pageCodeRootDir = pageCodeRootDir;
	}

	public List<BcrudCfgTableObj> getCfgTables() {
		return cfgTables;
	}

	public void setCfgTables(List<BcrudCfgTableObj> dataTables) {
		this.cfgTables = dataTables;
	}

	public String getMapperXmlPackageName() {
		return mapperXmlPackageName;
	}

	public void setMapperXmlPackageName(String mapperXmlPackageName) {
		this.mapperXmlPackageName = mapperXmlPackageName;
	}

    public boolean isHasCreateCtrler() {
        return hasCreateCtrler;
    }

    public void setHasCreateCtrler(boolean hasCreateCtrler) {
        this.hasCreateCtrler = hasCreateCtrler;
    }

    public boolean isHasCreatePage() {
        return hasCreatePage;
    }

    public void setHasCreatePage(boolean hasCreatePage) {
        this.hasCreatePage = hasCreatePage;
    }

	public List<FileOutputTpltCfg> getFileOutputTpltCfgList() {
		return fileOutputTpltCfgList;
	}

	public void setFileOutputTpltCfgList(List<FileOutputTpltCfg> fileOutputTpltCfgList) {
		this.fileOutputTpltCfgList = fileOutputTpltCfgList;
	}

	public String getProjRootDir() {
		return projRootDir;
	}

	public void setProjRootDir(String projRootDir) {
		this.projRootDir = projRootDir;
	}

	public boolean isHasCreateService() {
		return hasCreateService;
	}

	public void setHasCreateService(boolean hasCreateService) {
		this.hasCreateService = hasCreateService;
	}

	public String getDbType() {
		return dbType;
	}

	public void setDbType(String dbType) {
		this.dbType = dbType;
	}

    public String getProjPackageName() {
        if(Objects.isNull(projPackageName) ) {
            String calcPackage = this.getBasePackageName();
            if(calcPackage.endsWith("crud")) {
                int idx = calcPackage.lastIndexOf(".");
                if(idx > 0 ) {
                    calcPackage = calcPackage.substring(0,idx);
                    projPackageName = calcPackage;
                }
            }else {
                projPackageName = calcPackage;
            }
        }
        return projPackageName;
    }

    public void setProjPackageName(String projPackageName) {
        this.projPackageName = projPackageName;
    }

}
